package gbench.appdemo.mall.data;

import static gbench.common.tree.LittleTree.MFT;
import java.util.List;
import gbench.common.tree.LittleTree.IRecord;
import gbench.commonApp.data.DataApp;
/**
 * 
 * 
 * @author gbench
 *
 */
public class MallDataApp extends DataApp {

    /**
     * 
     * @param name 数据库名称
     */
    public MallDataApp(String dbname) {
        this.dbname = dbname;
        this.reload(this.configureDbName(dbname));
    }

    /**
     * 数据查询
     * 
     * @param sql sql 语句
     * @return IRecord 集合
     */
    public List<IRecord> sqlquery(final String sql, String dbname) {
        reload(this.configureDbName(dbname));
        return this.jdbc.sql2records(sql);
    }

    /**
     * 数据查询
     * 
     * @param sql sql 语句
     * @return IRecord 集合
     */
    public List<IRecord> sqlquery(final String sql) {
        return this.sqlquery(sql, dbname);
    }

    /**
     * 配置数据库
     * 
     * @param dbname
     * @return 设定数据库
     */
    public IRecord configureDbName(final String dbname) {
        return cfg.derive("url", MFT("jdbc:mysql://localhost:3306/{0}?serverTimezone=GMT%2B8", dbname));
    }

    private String dbname; // 数据库名称

}